<?php include view_path() . 'header_total.php'; ?>
<link rel="stylesheet" type="text/css" href="<?php echo css_url() . 'post_style.css' ?>">
<link rel="stylesheet" type="text/css" href="<?php echo css_url() . 'body_general.css' ?>">
<link rel="stylesheet" type="text/css" href="<?php echo css_url() . '960grid/960_extra.css'?>">
<link rel="stylesheet" type="text/css" href="<?php echo css_url() . '960grid/960.css'?>">
<link rel="stylesheet" type="text/css" href="<?php echo css_url().'JPag.css'?>" media="screen"/>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css">
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<section id="body">
    <div class="body-container">
        <div class="tab-titles">
            <div class="container_12">
                <a href="<?php echo site_url().'/user_group3/manage_jobs/' ?>">
                    <div class="grid_3 tab-entities">Applied Jobs</div>
                </a> 
                <a href="<?php echo site_url().'/user_group3/manage_jobs?section=favorite_posts' ?>">
                    <div  class="grid_3 tab-entities" clicked>Favorite Posts</div>
                </a>
            </div>
        </div>
        <div class="pagination-container" >
                        <div class="pagination"> </div>
        </div>
        <div>
        <?php if(count($Posts) > 0){ ?>
        <?php foreach ($Posts as $Post): ?>
            <div class="post-container">
                <a href="<?php echo site_url() . "/user_group3/jobs/" . $Post['PostID']; ?>">
                    <div class="image-holder">
                        <image src="<?php echo $Post['PictureURL'] ?>"/>
                    </div>
                </a>

                <div class="content-holder">
                    <input type="hidden" value="<?php echo $Post['PostID'] ?>">

                    <a href="<?php echo site_url() . "/user_group3/jobs/" . $Post['PostID']; ?>">
                        <div class="content-head"><?php echo $Post['Subject'] ?></div>
                    </a>
                    <p class="content"><?php echo $Post['Content'] ?>
                        <a href="<?php echo site_url() . "/user_group3/jobs/" . $Post['PostID']; ?>" class="more">See more</a>
                    </p>


                    <div style="display: inline; visibility: hidden" class="function-post-btns" > 
                        <?php if (!$Post['IsFavorite']) { ?>
                            <div class="add-favorite-btn" > &nbsp; &nbsp; &nbsp; </div>
                        <?php } else { ?>
                            <div class="add-favorite-btn-clicked" > &nbsp; &nbsp; &nbsp; </div>
                        <?php } ?>
                    </div>

                </div>


            </div>
            <div class="hr"> &nbsp;</div>
        <?php endforeach; ?>
        </div>
        <div class="pagination-container">
                    <div class="pagination"> </div>
        </div>

    </div>
        <?php }else{?>
    <div>No Post Found !</div>
        <?php }?>
</section>

<script src="<?php echo js_url().'jquery.paginate.js'?>" type="text/javascript"></script>
<script>
    $('.content-holder').on('mouseenter', function(){
        $(this).children('.function-post-btns').css('visibility', 'visible');
    });
    $('.content-holder').on('mouseleave', function(){
        $(this).children('.function-post-btns').css('visibility', 'hidden');
    });
 
    var addfavorite = function (){
        $('.add-favorite-btn').on('click', function () {
            var PostID = $(this).parent().siblings('input').val();
            var UserEmail = '<?php echo $UserInfo['UserEmail']; ?>';
            var url_link = "<?php echo site_url() . '/user_group3/jobs/add_favorite' ?>";
            result = "0";
            $("#dialog" ).dialog( "open" );
            $.ajax({
            url : url_link,
                    type: 'POST',
                    data: { PostID : PostID, UserEmail : UserEmail },
                    async: false,
                    success: function(data){
                    result = data;
                    }
            });
            if(result == 1){
                $(this).attr('class', 'add-favorite-btn-clicked');
                removefavorite();
            }
            
            
        });
    }

    var removefavorite = function(){
        $('.add-favorite-btn-clicked').on('click', function () {
            var PostID = $(this).parent().siblings('input').val();
            var UserEmail = '<?php echo $UserInfo['UserEmail']; ?>';
            var url_link = "<?php echo site_url() . '/user_group3/jobs/remove_favorite' ?>";
            result = "0";
            $.ajax({
            url : url_link,
                    type: 'POST',
                    data: { PostID : PostID, UserEmail : UserEmail },
                    async: false,
                    success: function(data){
                        result = data;
                    }
            });
            if(result == 1){
                $(this).attr('class', 'add-favorite-btn');
                addfavorite();
            }
            
        });
    }
    
    addfavorite();
    removefavorite();
    
    //Page Indexing
    TotalNum = <?php echo $TotalNum; ?>;
    <?php 
        $CurURL = curPageURL();
        if(strpos($CurURL, "&Page=")){
            $CurURL = substr($CurURL, 0, -7);
            $CurURL .= "&Page=";
        }else if(strpos($CurURL, "?Page=")){
            $CurURL = substr($CurURL, 0, -7);
            $CurURL .= "?Page=";
        }else{
            $CurURL .= "?Page=";
        }
    ?>
    $(function() {
            $(".pagination").paginate({
                    count 		: Math.ceil(TotalNum/10),
                    start 		: <?php echo $Current_Page; ?>,
                    display     : 7,
                    border					: true,
                    border_color			: '#fff',
                    text_color  			: '#FB6280',
                    background_color    	: '#FFF',	
                    border_hover_color		: '#FB6280',
                    text_hover_color  		: '#FFF',
                    background_hover_color	: '#FB6280', 
                    images					: false,
                    mouse					: 'mousedown',
                    link                        : '<?php echo $CurURL;?>',
                    onChange     			: function(page){

                    }
            });
    });

</script>

<?php include view_path().'footer.php'; ?>